﻿using NHibernate;
using NHibernate.Cfg;
using Rhinestone.Shared;

namespace LinqRepositorySample.Data.NHibernate
{

    public class NHibernateUnitOfWorkFactory : IUnitOfWorkFactory
    {
        #region fields
        private static ISessionFactory _sessionFactory;
        #endregion

        #region .ctor
        static NHibernateUnitOfWorkFactory ()
        {
            Configuration config = new Configuration()
                                    .Configure()
                                    .AddAssembly(typeof (NHibernateUnitOfWorkFactory).Assembly);
            _sessionFactory = config.BuildSessionFactory();
        }
        #endregion

        #region methods
        public IUnitOfWork Create()
        {
            ISession session = _sessionFactory.OpenSession();
            return new NHibernateUnitOfWork(session);
        }
        #endregion
    }
}
